home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 126-150 / scopedisk146 / liner / source / color.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  5KB  |  191 lines

  1. /*Color.c*/
  2. /*Puts up a color requestor to get the screen colors for 'Liner*/
  3.  
  4. #include <exec/types.h>
  5. #include <intuition/intuition.h>
  6. #include <exec/exec.h>
  7.  
  8. #include "ColorWdw.h"
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11. struct GfxBase *GfxBase;
  12.  
  13. struct Window *Wdw;
  14.  
  15. #define Rp Wdw->RPort
  16. #define Vp Wdw->WScreen->ViewPort
  17.  
  18. #define RED 1
  19. #define GREEN 2
  20. #define BLUE 3
  21.  
  22. extern ColorReq();
  23. void UpdateColorReg();
  24. void RestoreColors();
  25.  
  26. ColorReq(Scrn)
  27. struct Screen *Scrn;
  28. {
  29.    struct Gadget *it;
  30.    struct PropInfo *prop;
  31.    
  32.    ULONG Class;
  33.    SHORT MouseX;
  34.    USHORT color=0;
  35.    struct IntuiMessage *mesg;
  36.    USHORT CurrentGadget;
  37.    USHORT Colors[4];
  38.    ULONG OldColors[4];
  39.    BYTE c;
  40.    
  41.    ULONG rgb;
  42.    
  43.    if(Scrn == NULL)
  44.       NewWindowStructure1.Type=WBENCHSCREEN;
  45.    else
  46.    {
  47.       NewWindowStructure1.Type=CUSTOMSCREEN;
  48.       NewWindowStructure1.Screen=(struct Screen *)Scrn;
  49.    }
  50.    
  51.    Wdw=(struct Window *)OpenWindow(&NewWindowStructure1);
  52.    if(Wdw==NULL)
  53.       return(FALSE);
  54.  
  55.    SetAPen(Rp,1);
  56.    RectFill(Rp,9+64,53,9+127,64);
  57.    SetAPen(Rp,2);
  58.    RectFill(Rp,9+128,53,9+191,64);
  59.    SetAPen(Rp,3);
  60.    RectFill(Rp,9+192,53,9+255,64);
  61.    PrintIText(Rp,&IntuiTextList1,0,0);
  62.    
  63.       /*Store the colors before we do anything*/
  64.    for(c=0;c<4;c++)
  65.       OldColors[c]=GetRGB4(Vp.ColorMap,c);
  66.    
  67.    rgb=GetRGB4(Vp.ColorMap,0);
  68.    RedSliderSInfo.HorizPot=(Colors[RED]=(rgb >> 8) & 0xF)<<12;
  69.    GreenSliderSInfo.HorizPot=(Colors[GREEN]=(rgb >> 4) & 0xF)<<12;
  70.    BlueSliderSInfo.HorizPot=(Colors[BLUE]=rgb & 0xF)<<12;
  71.    
  72.    UpdateNum(RED,Colors[RED]);
  73.    UpdateNum(GREEN,Colors[GREEN]);
  74.    UpdateNum(BLUE,Colors[BLUE]);
  75.  
  76.    RefreshGadgets(&RedSlider,Wdw,NULL);  
  77.    
  78.    for(;;)
  79.    {
  80.       Wait(1<<Wdw->UserPort->mp_SigBit);
  81.       while((mesg=(struct IntuiMessage *)GetMsg(Wdw->UserPort))!=NULL)
  82.       {
  83.          it=(APTR)mesg->IAddress;
  84.          Class=mesg->Class;
  85.          MouseX=mesg->MouseX;
  86.          ReplyMsg(mesg);
  87.          
  88.          switch(Class)
  89.          {
  90.             case GADGETUP:
  91.                RestoreColors(OldColors,color,Colors);
  92.                break;
  93.             case CLOSEWINDOW:
  94.                CloseWindow(Wdw);
  95.                return(TRUE);
  96.             case MOUSEMOVE:
  97.                UpdateNum(CurrentGadget,
  98.                      (Colors[CurrentGadget]=(prop->HorizPot >> 12)));
  99.                UpdateColorReg(color,Colors,&Vp);
  100.                break;
  101.             case GADGETDOWN:
  102.                CurrentGadget=it->GadgetID;
  103.                if(CurrentGadget < 4)
  104.                {
  105.                   prop=(APTR)it->SpecialInfo;
  106.                   UpdateNum(CurrentGadget,(Colors[CurrentGadget]=
  107.                         (prop->HorizPot) >> 12 ));
  108.                   UpdateColorReg(color,Colors,&Vp);
  109.                }
  110.                else
  111.                {
  112.                   color=(MouseX-9)/64;
  113.                   rgb=GetRGB4(Vp.ColorMap,color);
  114.                   RedSliderSInfo.HorizPot=(Colors[RED]=(rgb >> 8) & 0xF)<<12;
  115.                   GreenSliderSInfo.HorizPot=(Colors[GREEN]=(rgb >> 4) & 0xF)<<12;
  116.                   BlueSliderSInfo.HorizPot=(Colors[BLUE]=rgb & 0xF)<<12;
  117.       
  118.                   UpdateNum(RED,Colors[RED]);
  119.                   UpdateNum(GREEN,Colors[GREEN]);
  120.                   UpdateNum(BLUE,Colors[BLUE]);
  121.  
  122.                   RefreshGadgets(&RedSlider,Wdw,NULL);
  123.                   SetAPen(Rp,color);
  124.                   RectFill(Rp,290,17,310,47);
  125.                }
  126.          }
  127.       }
  128.    }
  129. }
  130.  
  131. UpdateNum(Color,value)
  132. USHORT Color,value;
  133. {
  134.    char Num[4];
  135.  
  136.    if(value > 15)
  137.       return(FALSE); /*Get rid of funny answers*/
  138.    SetAPen(Rp,1);
  139.    Move(Rp,15,15+(Color*10));
  140.    
  141.    if(value > 9)
  142.       stci_d(Num,value);
  143.    else
  144.    {
  145.       stci_d(&Num[1],value);
  146.       Num[0]=' ';
  147.    }
  148.    Text(Rp,Num,2);
  149.    return(TRUE);
  150. }
  151.  
  152. void UpdateColorReg(reg,colors,ViewPort)
  153. USHORT reg,*colors;
  154. struct ViewPort *ViewPort;
  155. {
  156.    SetRGB4(ViewPort,reg,colors[RED],colors[GREEN],colors[BLUE]);
  157. }
  158.  
  159. void RestoreColors(OldColors,curreg,Colors)
  160. ULONG *OldColors;
  161. BYTE curreg;
  162. USHORT *Colors;
  163. {
  164.    BYTE c;
  165.    USHORT red,green,blue;
  166.    
  167.    for(c=0;c<4;c++)
  168.    {
  169.       red = (OldColors[c]>>8) & 0xF;
  170.       green = (OldColors[c]>>4) & 0xF;
  171.       blue = OldColors[c] & 0xF;
  172.       SetRGB4(&Vp,c,red,green,blue);
  173.       if(c==curreg)
  174.       {
  175.          RedSliderSInfo.HorizPot=(Colors[RED]=red)<<12;
  176.          
  177.          GreenSliderSInfo.HorizPot=(Colors[GREEN]=green)<<12;
  178.          
  179.          BlueSliderSInfo.HorizPot=(Colors[BLUE]=blue)<<12;
  180.    
  181.          UpdateNum(RED,Colors[RED]);
  182.          UpdateNum(GREEN,Colors[GREEN]);
  183.          UpdateNum(BLUE,Colors[BLUE]);
  184.          RefreshGadgets(&RedSlider,Wdw,NULL);  
  185.  
  186.       }
  187.    }
  188. }
  189.  
  190. /*End of color.c*/
  191.